<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		
	
		
		
	</body>
<script type="text/javascript">
	


 //排序
  /*
var c=[25,37,29,15,18,56,66];
	function sort1(arr,d){
	var text=0;
	for(var i=0;i<arr.length;i++){
		for(var j=0;j<arr.length;j++){
			if(eval([arr[i]+d+arr[j]])){
				text=arr[j];
				arr[j]=arr[i];
				arr[i]=text;
			}
		}
	}
	return arr;
}
document.write(sort1(c,"<")+"<br/>")
*/		



//数组去重
/*
	var arr=[1,2,5,6,2,1,9,"a","b","d","b","a"];
	var arr1=[];
	for(var i=0;i<arr.length;i++){
		// arr[i]    1,2,5,6,2,1,9,"a","b","d","b","a"
		if(arr1.indexOf(arr[i] )==-1){
			arr1.push(arr[i])
		}
	}document.write(arr1+"<br/>")
*/	



//传参写出  数组去重
/*
	var arr=[1,2,5,6,2,1,9,"a","b","d","b","a"]
	var arr1=[];
	function fun(arr){
		for(var i=0;i<arr.length;i++){
			if(arr1.indexOf(arr[i] )==-1){
				arr1.push(arr[i])
			}
		}
		document.write(arr1+"<br/>")
	}
	fun(arr)
*/


	//    排序
/*	
	var a= [1111,2022,33,4,555];
    a.sort(sortNumber)
    function sortNumber(a,b){
       return a - b
    }
	document.write(a.join(" , "))
*/







// 排序方法一  用快速排序法来排序
          function paixun(arr){
           if(arr.length<=1){ return arr}
               let ban=Math.floor(arr.length/2);
               let left=[];
               let right=[];
               let index=arr.splice(ban,1)[0]
               for(let i=0;i<arr.length;i++){
                 if(arr[i]<index){
                   left.push(arr[i])
                 }
                 else{
                   right.push(arr[i])
                 }
               }
               return paixun(left).concat([index],paixun(right))
             }
         document.write(paixun([5,6,8,5,2,2,2,5,9,12,65,48])+'<br />')
      
      
      
      // 排序方法二 用冒泡排序法
       	var arr=[5,6,8,5,2,2,2,5,9,12,65,48]
           for(let i=0;i<arr.length;i++){
             for(let j=i+1;j<arr.length;j++){
               if(arr[i]<=arr[j]){
                 let num=arr[j];
                 arr[j]=arr[i];
                 arr[i]=num
               }
             }
           }
      	document.write(arr+'<br />')


 //去重方法一
 		var arr=[5,6,8,5,2,2,2,5,9,12,65,48]
	      let arr1=[]
	      for(let i=0;i<arr.length;i++){
	         if(arr1.indexOf(arr[i])==-1){
	         	arr1.push(arr[i])
	         }
	      }
	    document.write(arr1+'<br />')
     
    //去重方法二
        var arr=[5,6,8,5,2,2,2,5,9,12,65,48]
	        for(let i=0;i<arr.length;i++){
	        	for(let j=i+1;j<=arr.length-1;j++){
	        		if(arr[i]==arr[j]){
	        			console.log(i+":"+j)
	        			arr.splice(j,1);
	             j--;
	        		}
	        	}
	        }
        document.write(arr)


	
	
	
	
</script>	
</html>
